<select name="<?php echo $name ?>" id="<?php echo isset($id) ? $id : $name ?>">
    <?php
    foreach ($posts as $post) {
    ?>
        <option value="<?php echo $post['id'] ?>"><?php echo $post['title'] ?></option>
    <?php
    }
    ?>
</select>